<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@include file="/WEB-INF/webpage/common/taglibs.jspf"%>
<!DOCTYPE html>
<html>
<head>
  <title><spring:message code="sys.dict.group.title" /></title>
  <meta name="decorator" content="list"/>
</head>
<body title="<spring:message code="sys.dict.group.title" />">
<grid:grid id="groupGridId"  baseUrl="${adminPath}/sys/dict/group">
	<grid:column label="sys.common.key" hidden="true"   name="id" width="100"/>
	<grid:column label="sys.common.opt"  name="opt" formatter="button" width="100" sortable="false"/>
	<grid:button title="sys.dict.group.adddict"  groupname="opt" function="rowDialogDetailRefresh" outclass="btn-primary"  innerclass="fa-plus" url="${adminPath}/sys/dict?gid=\"+row.id+\"" />
	<grid:button  groupname="opt" function="delete"  />
    <grid:column label="sys.dict.group.name"  name="name"  query="true" condition="like" />
    <grid:column label="sys.dict.group.code"  name="code"  query="true" condition="like" />
	<grid:column label="sys.dict.group.delFlag"  name="delFlag" dict="sf" query="true" queryMode="select" />
	<grid:column label="sys.dict.group.dataPermissionFlag"  name="dataPermissionFlag" dict="sf" query="true" queryMode="select" />
    
	<grid:toolbar   function="create"  />
	<grid:toolbar   function="update"    />
	<grid:toolbar   function="delete"    />
	<grid:toolbar title="启用" icon="fa-file-text-o" onclick="updateState('0')"/>
	<grid:toolbar title="停用" icon="fa-file-text-o" btnclass="btn-warning" onclick="updateState('1')"/>
	<grid:toolbar   title="强制刷新"   icon="fa-refresh"  onclick="forceRefresh()"  />
	<grid:toolbar title="清除缓存" icon="fa-file-text-o" btnclass="btn-warning" onclick="clearCache()"/>
	<grid:toolbar  function="search"  />
	<grid:toolbar  function="reset"  />
</grid:grid>
<script>
	/**
	 * 强制刷新
	 */
	function forceRefresh() {
		   swal({
				title: "提示",
				text: "您确定强制刷新字典！",
				type: "warning",
				showCancelButton: true,
				confirmButtonColor: "#DD6B55",
				confirmButtonText: "确定",
				closeOnConfirm: false,
				cancelButtonText: "取消",
			}, function () {
				$.ajax({
					url : '${adminPath}/sys/dict/group/forceRefresh',
					type : 'post',
					cache : false,
					success : function(d) {
						if (d.ret==0) {
							var msg = d.msg;
							swal("提示！", msg, "success");
						}else{
							var msg = d.msg;
							swal("提示！", msg, "error");
						}
					}
				});
			});
	 }

	/**
	 * 修改状态
     * @param state
	 */
	function updateState(state) {
		var selectedRows = $("#groupGridIdGrid").jqGrid('getGridParam','selarrrow');
		var ids = [];
		// 如果没有选择，提示
		if (selectedRows.length == 0) {
			top.layer.alert('请至少选择一条数据!', {icon: 0, title:'警告'});
			return;
		}
		// 获取装车单号
		for (var i = 0; i < selectedRows.length; i++) {
			ids.push($("#groupGridIdGrid").jqGrid('getRowData', selectedRows[i]).id);
		}

		// POST请求发车确认
		$.ajax({
			type: "POST",
			url: "${adminPath}/sys/dict/group/updateState",
			data: {
				ids : ids,
				state : state
			},
			traditional: true,
			success: function (data) {
				if (data.ret == 0) {
					top.layer.alert(data.msg, {icon: 0, title:'提示'});
					//刷新表单
					refreshTable("groupGridIdGrid");
				}
				else {
					top.layer.alert(data.msg, {icon: 0, title:'提示'});
				}
			}
		});
	}

	function clearCache() {
		// POST请求发车确认
		$.ajax({
			type: "GET",
			url: "${adminPath}/sys/dict/group/clearCache",
			traditional: true,
			success: function (data) {
				if (data.ret == 0) {
					top.layer.alert(data.msg, {icon: 0, title:'提示'});
				}
				else {
					top.layer.alert(data.msg, {icon: 0, title:'提示'});
				}
			}
		});
	}
</script>
</body>
</html>